import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 28463
 * Date: 2022—08—17
 * Time: 15:56
 */
public class librarySelect {
    public static void main(String[] args) throws SQLException {
        //1.创建数据源
        DataSource dataSource = new MysqlDataSource();
        ((MysqlDataSource)dataSource).setURL("jdbc:mysql://127.0.0.1:3306/ebook?characterEncoding=utf8&useSSL=false");
        ((MysqlDataSource)dataSource).setUser("root");
        ((MysqlDataSource)dataSource).setPassword("111111");

        //2.连接数据库
        Connection connection = dataSource.getConnection();

        //3.构造sql语句
        String sql = "delete from borrow_info order by id desc limit 1";

        PreparedStatement statement = connection.prepareStatement(sql);

        //4.执行SQL语句
        int n = statement.executeUpdate();
        System.out.println("n = " + n);

        //5.释放资源
        statement.close();
        connection.close();

    }
}
